#include <iostream>
#include <string.h>
#include "Comm.hpp"


int main()
{
    char buffer[1024];
    SetNonBlock(0);
    while(true)
    {
        ssize_t s = ::read(0,buffer,sizeof(buffer)-1);
        if(s > 0)
        {
            buffer[s] = 0;
            std::cout << "Echo# "<< buffer <<std::endl;
        }
        else
        {
            //底层数据没有就绪错误码就会被设置成下面两个
            if(errno == EWOULDBLOCK || errno == EAGAIN)
            {
                std::cout << "底层数据没有就绪, 下次在试试吧! 做做其他事情！" << std::endl;
                sleep(1);
                continue;
            }
            std::cout <<"读取错误... s"<< s <<" errno: "<< errno << " "<< strerror(errno)<<std::endl; 
        }
        sleep(1);
    }


    return 0;
}